package com.mine;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.junit.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class CacheLoaderDemos {
  @Test
  public void loadingCacheTest() throws ExecutionException {
    LoadingCache<Integer, String> loadingCache = CacheBuilder.newBuilder()
        .expireAfterAccess(1, TimeUnit.SECONDS)
        .build(new CacheLoader<Integer, String>() {
          @Override
          public String load(Integer o) throws Exception {
            return "123";
          }
        });
    System.out.println(loadingCache.getUnchecked(1));
  }
}
